package com.jerry.server;

public abstract  class AbstractEndpoint<T> {
    protected volatile  boolean isRunning = false;

    protected volatile boolean paused = false;

   private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isRunning(){


        return isRunning;
    }

    public boolean isPaused(){
        return  paused;
    }
    public void startInternal(){
        if(!isRunning){
            isRunning = true;
            paused = false;
        }



    }
    private void startAcceptorThread(){
        Acceptor acceptor = new Acceptor(this);
        String threadName = getName() + "-Acceptor";
        acceptor.setThreadName(threadName);
        Thread t = new Thread(acceptor, threadName);
        t.setDaemon(true);
        t.start();
    }

    public void pause(){

        paused = true;


    }
    public abstract <T>   T serverSocketAccept() throws Exception;
    public abstract void bind() throws Exception;

    public abstract  boolean setSocketOptions(T socket);

    public abstract  void closeSocket(T socket);

    public abstract void destroySocket(T socket);

}
